﻿using Amiable.SDK.Wrapper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Amiable.Core.BotEvents.Models;
using Amiable.SDK;

namespace Amiable.Core.BotEvents
{
    class XdXd
    {
        public static XdConfiguration Configuration;

        public static HttpListener Listener;

        public static IApiWrapper Api;

        public static void LoadConfig()
        {
            var path = Path.Combine(Directory.GetCurrentDirectory(), "Ami", "XdXdBot", "appsettings.json");

            Directory.CreateDirectory(Path.GetDirectoryName(path) ?? string.Empty);

            if (File.Exists(path) is false)
            {
                File.WriteAllText(path, JsonSerializer.Serialize(
                    XdConfiguration.GetDefault()));
                Configuration = XdConfiguration.GetDefault();
            }

            try
            {
                Configuration = JsonSerializer.Deserialize<XdConfiguration>(File.ReadAllText(path));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
    }
}